<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单编号：</label>
                                <input type="text" name="orderId"/>
                            </li>
                            <li>
                                <label>客户编号：</label>
                                <input type="text" name="custNo"/>
                            </li>
                            <li>
                                <label>车辆编号：</label>
                                <input type="text" name="carId"/>
                            </li>
                            <li>
                                <label>订单状态：</label>
                                <select name="orderStatus" th:with="type=${@dict.getType('sys_order_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>租车时间：</label>
                                <input type="text" class="time-input" id="beginRentTime" placeholder="开始时间" name="params[beginRentTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endRentTime" placeholder="结束时间" name="params[endRentTime]"/>
                            </li>
                            <li>
                                <label>预计还车时间：</label>
                                <input type="text" class="time-input" id="beginExpectReturnTime" placeholder="开始时间" name="params[beginExpectReturnTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endExpectReturnTime" placeholder="结束时间" name="params[endExpectReturnTime]"/>
                            </li>
                            <li>
                                <label>实际还车时间：</label>
                                <input type="text" class="time-input" id="beginActualReturnTime" placeholder="开始时间" name="params[beginActualReturnTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endActualReturnTime" placeholder="结束时间" name="params[endActualReturnTime]"/>
                            </li>
                            <li>
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="beginCreateTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endCreateTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <label>修改时间：</label>
                                <input type="text" class="time-input" id="beginUpdateTime" placeholder="开始时间" name="params[beginUpdateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endUpdateTime" placeholder="结束时间" name="params[endUpdateTime]"/>
                            </li>
                            <li>
                                <label>总金额：</label>
                                <input type="text" id="allPrice1" name="params[allPrice1]"/>
                                <span>-</span>
                                <input type="text" id="allPrice2" name="params[allPrice2]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="lease:order:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('lease:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('lease:order:remove')}]];
        var viewFlag = [[${@permission.hasPermi('lease:order:view')}]];
        var cancelFlag = [[${@permission.hasPermi('lease:order:cancel')}]];
        var orderStatusDatas = [[${@dict.getType('sys_order_status')}]];
        var prefix = ctx + "lease/order";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                detailUrl: prefix + "/preview/{id}",
                // cancelUrl: prefix + "/cancel",
                exportUrl: prefix + "/export",
                modalName: "订单管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'orderId',
                    title: '订单编号'
                },
                {
                    field: 'custNo',
                    title: '客户编号'
                },
                {
                    field: 'carId',
                    title: '车辆编号'
                },
                {
                    field: 'orderStatus',
                    title: '订单状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'rentTime',
                    title: '租车时间'
                },
                {
                    field: 'expectReturnTime',
                    title: '预计还车时间'
                },
                {
                    field: 'actualReturnTime',
                    title: '实际还车时间'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    visible: false
                },
                {
                    field: 'updateTime',
                    title: '修改时间',
                    visible: false
                },
                {
                    field: 'rentPrice',
                    title: '租车金额',
                    visible: false
                },
                {
                    field: 'dayPrice',
                    title: '按天单价',
                    visible: false
                },
                {
                    field: 'delayHourPrice',
                    title: '超时单价/时',
                    visible: false
                },
                {
                    field: 'damagePrice',
                    title: '损坏金额',
                    visible: false
                },
                {
                    field: 'delayDayPrice',
                    title: '超时单价/天',
                    visible: false
                },
                {
                    field: 'delayPrice',
                    title: '超时金额',
                    visible: false
                },
                {
                    field: 'deposit',
                    title: '押金',
                    visible: false
                },
                {
                    field: 'allPrice',
                    title: '总金额'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + viewFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.orderId + '\')"><i class="fa fa-eye"></i>预览</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="confirm_order(\'' + row.orderId + '\',\'' + row.carId + '\',\'' + row.custNo + '\',\'' + row.orderStatus + '\')"><i class="fa fa-check"></i>确认</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit_order(\'' + row.orderId + '\',\'' +  row.orderStatus + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="return_car(\'' + row.orderId + '\',\'' + row.carId + '\',\'' + row.custNo + '\',\'' + row.orderStatus + '\')"><i class="fa fa-mail-reply"></i>还车</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="cancel(\'' + row.orderId + '\',\'' + row.carId + '\',\'' + row.custNo + '\',\'' + row.orderStatus + '\')"><i class="fa fa-remove"></i>取消</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function confirm_order(orderId, carId, custNo, orderStatus) {
            if (orderStatus == '3') {
                $.operate.get( prefix + '/confirm/' + orderId + '/' + carId + '/' + custNo)
            } else {
                $.modal.msgError('该订单不能确认！');
                return;
            }
        }

        function edit_order(orderId, orderStatus) {
            if (orderStatus == '3') {
                $.operate.edit(orderId)
            } else {
                $.modal.msgError('该订单不能编辑！');
                return;
            }
        }

        function return_car(orderId, carId, custNo, orderStatus) {
            if (orderStatus == '0') {
                // var url = prefix + '/return_car/' + orderId + '/' + carId + '/' + custNo;
                var url = prefix + '/return_car/' + orderId;
                $.modal.open('还车', url, '900', '500');
            } else {
                $.modal.msgError('该订单不能还车！');
                return;
            }
        }

        function cancel(orderId, carId, custNo, orderStatus) {
            if (orderStatus == '3') {
                $.operate.get( prefix + '/cancel/' + orderId + '/' + carId + '/' + custNo)
            } else {
                $.modal.msgError('该订单不能取消！');
                return;
            }
        }

    </script>
</body>
</html>